<template>
    <!-- 商品排行 -->
    <div class="rank">
        <div class="tab">
            <h3>热卖排行</h3>
        </div>

        <div class="content">
            <ul>
                <li>
                    <router-link :to="`/detail/${item.goods_id}`" target="_blank" v-for="(item,i) in goodsList" :key="i" >
                        <div class="img-item">
                            <p class="tab-pic">
                                <a >
                                    <img :src="item.goods_img" />
                                </a>
                            </p>
                            <div class="tab-info">
                                <div class="info-title">
                                    <a >{{ item.goods_title}}</a>
                                </div>
                                <p class="info-price">¥{{ item.goods_price }}</p>
                            </div>
                        </div>
                    </router-link>
                </li>
                
            </ul>
        </div>
    </div>
</template>

<script>
export default {
    name: 'Rank',
    data() {
        return {
            categoryId:[1,2,3,4,5,6,7,8,9],
            goodsList:[]
        };
    },

    mounted() {
        this.getGoodsList()
    },

    methods: {
        //这里只是拿到数据库所有数据然后截取
        async getGoodsList() {
            const res = await this.$API.reqGetGoodsByCategory(this.categoryId);
            if (res.code == 200) {
                //这里以后可以做获得到得数据排行（后台做较好）
                this.goodsList = res.data.slice(res.data.length-4, res.data.length)
            }
            console.log(this.goodsList)
        },
        
    },
};
</script>

<style  scoped>
.rank {
    width: 1200px;
    margin: 0 auto;
    margin-top: 30px;
}

.rank .tab {
    overflow: hidden;
}

.rank .tab h3 {
    font-size: 20px;
}


.rank .content {
    overflow: hidden;
    padding: 10px 0;
}

.rank .content ul li {
    overflow: hidden;
    list-style: none;
    line-height: 18px;
    display: flex;
    justify-content: space-between;
}

.rank .content ul li a {

    text-decoration: none;

}

.rank .content ul li .img-item {
    border: 1px solid pink;
    width: 269px;
    overflow: hidden;
    background: #fff;
}

.rank .content ul li .img-item .tab-pic {
    width: 230px;
    height: 210px;
    overflow: hidden;
    text-align: center;
    margin: 5px auto 18px;
}

.rank .content ul li .img-item .tab-pic a img {
    width: 200px;
    height: 200px;
}

.rank .content ul li .img-item .tab-info {
    background: #fafafa;
}

.rank .content ul li .img-item .tab-info .info-title {
    height: 50px;
    line-height: 28px;
    overflow: hidden;
    margin: 0 auto;
 
    padding: 0 15px;
    text-overflow: ellipsis

}

.rank .content ul li .img-item .tab-info .info-title a {
    color: #333;
   
}

.rank .content ul li .img-item .tab-info .info-price {
    font-size: 20px;
    color: #e1251b;
    height: 35px;
    padding-left: 30px;
    line-height: 24px;
    margin: 10px auto 0;
}
</style>